package com.linq.cool.beauty.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.linq.cool.beauty.domain.BeautyOrderEvaluation;
import com.linq.cool.beauty.dto.BeautyOrderEvaluationDTO;
import com.linq.cool.beauty.dto.BeautyOrderEvaluationQueryDTO;
import com.linq.cool.beauty.service.BeautyOrderEvaluationService;
import com.linq.cool.common.core.domain.BaseController;
import com.linq.cool.common.core.domain.PageVO;
import com.linq.cool.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: yqlin
 * @Date: 2021/2/15 18:34
 * @Description:
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("orderEvaluation")
public class BeautyOrderEvaluationController extends BaseController {
    @Autowired
    private BeautyOrderEvaluationService orderEvaluationService;

    /**
     * 前台评价
     *
     * @return
     */
    @PostMapping("saveMemberOrderEvaluation")
    public Result<?> saveMemberOrderEvaluation(@RequestBody BeautyOrderEvaluationDTO dto) {
        orderEvaluationService.saveMemberOrderEvaluation(dto);
        return Result.ok("评价成功");
    }

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("list")
    public Result<?> list(BeautyOrderEvaluationQueryDTO dto) {
        IPage<BeautyOrderEvaluation> page = orderEvaluationService.listByPage(dto.getPage(), dto);
        return Result.ok(new PageVO().setRecords(page.getRecords()).setTotal(page.getTotal()));
    }

    /**
     * 前台获取指定商品的评价信息
     *
     * @return
     */
    @GetMapping("getProductEvaluations")
    public Result<?> getProductEvaluations(@RequestParam("productId") Long productId) {
        return Result.ok(orderEvaluationService.listProductEvaluations(productId));
    }
}
